<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>  
<!DOCTYPE html>
<html>
<head>
<title>角色管理列表</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="decorator" content="default" />
<%@ include file="/WEB-INF/views/include/bootstrap-table.jsp"%>
    
</head>
<body>
<div class="layui-fluid" style="">
    <div class="layui-row">
        <blockquote class="layui-elem-quote news_search">
            <form id="searchForm">
                   <input type="hidden" id="officeId" value="${param.officeId}"/>
		           <div class="layui-inline"> 
		                                   岗位名称：
		              <div class="layui-input-inline">
		                   <input id="name" name="name"  class="layui-input search_input" type="text">
		              </div>
		                                      英文名称：
		              <div class="layui-input-inline">
		                  <input id="enname" name="enname"  class="layui-input search_input" type="text">
		              </div>
		              <a  id="btn_search" class="layui-btn search_btn">查询</a>
		              <a  id="btn_reset" onclick="formResetBySearch_role();" class="layui-btn layui-btn-primary search_btn">重置</a>
		          </div>
					<script type="text/javascript">
						$(function(){
							$(".search-bar ul li").each(function(){
								var spanWidth = $(this).find("span").width();
								$(this).find(".form-control").width(230-20-spanWidth);	
								$(this).children(".input-append").find(".required").width(230-20-36+1-spanWidth);	
								var barHeight = $(".search-bar").height();
								$(".search-btn").css("line-height", barHeight+"px");
							});
						})
					</script>
			</form>	
		</blockquote>
</div>		
				<div id="toolbar">
					<div class="layui-btn-group">
					 <shiro:hasPermission name="sys:role:create">
						<button type="button" class="layui-btn layui-btn-normal" onclick="gotoView('${ctx}/sys/role/form');">新增</button>
						<button type="button" class="layui-btn layui-btn-normal" onclick="addUser('sys/role/assign',true)">添加用户</button>
					 </shiro:hasPermission>
					 <shiro:hasPermission name="sys:role:delete">
						<button type="button" class="layui-btn layui-btn-danger" onclick="batchDelete('sys/role/batchDelete')">批量删除</button>
					 </shiro:hasPermission>
					<%--<button type="button" class="btn-custom" onclick="exportData('${ctx}/sys/role/export',this)">导出</button>  --%>	
				    </div>	
				</div>
			
		
		
	    <table id="table" 
	         data-toggle="table" 
	         data-url="${ctx}/sys/role/roleListJson"
	         data-toolbar="#toolbar"
		     data-height="${dataHeight410}" 
		     data-maintain-selected="true" 
		     data-side-pagination="server"
		     data-click-to-select="true" 
		     data-pagination="true" 
		     data-single-select="false"
		     data-id-field="id"
		     data-query-params="doQuery"
		     data-cache="false"
		     data-show-columns="true"
		     data-page-list="${dataPageList}">
		<thead>
			<tr>
			    <th data-checkbox="true"></th>
			    <th data-field="id" data-formatter="operationFormatter" class="date-field-class">操作</th>
				<th data-field="name" data-sortable="true">岗位名称</th>
				<th data-field="enname" data-sortable="true" data-visible="false">英文名称</th>
			    <th data-field="office.name">归属机构</th>
				<th data-field="roleType" data-sortable="true" data-formatter="roleTypeFormatter">岗位类型</th>
				<th data-field="dataScope" data-sortable="true" data-formatter="dataScopeFormatter">数据范围</th>
				<th data-field="useable" data-sortable="true" data-formatter="useableFormatter">是否可用</th>
				<th data-field="usernum">用户数</th>
				<!--<th data-field="allOfficeName">归属机构</th> -->
				<!-- data-visible="false" 可以隐藏列 -->
			</tr>
		</thead>
	    </table>
</div>
	
	<script type="text/javascript">
	  var $table = $('#table');
	  $(function () { 
          
	      $("#btn_search").click(function () { 
	              $table.bootstrapTable('refresh'); 
	       }); 
	   }); 
	  
	  //查询函数
	  function doQuery(params) {
		     var name_value = $("#name").val();
			 var enname_value = $("#enname").val();
			 
			if(name_value != null && name_value !=''){
				params.name = name_value;
			}
			if(enname_value != null && enname_value !=''){
				params.enname = enname_value;
			}
			
			 var officeId = $("#officeId").val();
			 
			if(officeId != null && officeId !=''){
					params["office.id"] = officeId;
			}
			
		    return params;
	}
	
	//添加用户
	function addUser(url, istrue) {
			var isclose=istrue==true?true:false;
			var row_date_arr = $table.bootstrapTable('getSelections');
			
			if(row_date_arr.length > 1){
				showTip("只可以选择一条数据！", "info", undefined, undefined);
			    return false;
			}
			if(row_date_arr.length == 0){
				showTip("请选择一条数据！", "info", undefined, undefined);
			    return false;
			}
			
			var param = '';
			$.each(row_date_arr,function (index,row){
				param = row.id;
			});
			
			url=url+"?id="+param;
			opencreateWindow(url,'添加用户',1000,600,'10px',istrue);
		}
	
	/**
	*  操作项  add for lgx  提供查看，修改，删除按钮，如果还有系统按钮，
	*  比如禁用，可在子页面进行自定义函数添加（建议列表操作项按钮不要超过5个）
	*/
	var hasView = '${fns:hasPermission("sys:user:view")}';
	var hasEdit = '${fns:hasPermission("sys:user:edit")}';
	var hasDelete = '${fns:hasPermission("sys:user:delete")}';
	
	function operationFormatter(value, row){
		
		var params = "id="+value;
	
		//
		var html = '';
		
		if(hasView == 'true'){
			//查看
			//html = html + '<a href="javascript:void(0);" style="padding-right:5px;" onclick="detail(\'sys/role/roleDetail\',\'查看角色\',\''+params+'\')">查看</a>';
		}else{
			//html = html + '<span style="padding-right:5px;" title="您没有操作权限">查看</span>';
		}
	
		if(hasEdit == 'true'){
			//修改
			html = html + '<a href="javascript:void(0);" class="layui-btn layui-btn-xs" onclick="gotoView(\'${ctx}/sys/role/form?'+params+'\');">修改</a>';
		}else{
			html = html + '<span class="layui-btn layui-btn-disabled layui-btn-xs" title="您没有操作权限">修改</span>';
		}

		if(hasDelete == 'true'){
			//删除
			html= html  + '<a href="javascript:void(0);" class="layui-btn layui-btn-danger layui-btn-xs"  onclick="deleteData(\'sys/role/deleteAjax\',\'是否删除数据？\',\''+params+'\')">删除</a>';
		}else{
			html = html + '<span  class="layui-btn layui-btn-disabled layui-btn-xs" title="您没有操作权限">删除</span>';
		}
		
		return html;
	}  
	
	function roleTypeFormatter(value, row){
		   var data = ${fns:getDictListJson('sys_role_type')}; 
		   value = getDictLabel(data,value,'-');
		   return value;
	}
	
	function dataScopeFormatter(value, row){
		   var data = ${fns:getDictListJson('sys_data_scope')}; 
		   value = getDictLabel(data,value,'-');
		   return value;
	}
	
	
	function useableFormatter(value, row){
		   var data = ${fns:getDictListJson('yes_no')}; 
		   value = getDictLabel(data,value,'-');
		   return value;
	}
	
	//自己定义Reset 事件
	function formResetBySearch_role(){
		   $("#officeId").val("");
	       document.getElementById("searchForm").reset();
	       $("#btn_search").click();
	}
	
	</script>
	
	<jsp:include page="/WEB-INF/views/include/pageJs.jsp" />
</body>
</html>